﻿@model Commission.ViewModels.CustomerInformation
@using MyResources = Commission.Resources.AppResource

@{
    ViewBag.Title = @MyResources.LabelCustomerInformation;
}

@section MyJavascript {
    <script type="text/javascript">
    $(function () {
        //$("#UserName").attr("disabled", "disabled");

        $('#UserName').autocomplete(
        {
            source: '@Url.Action("UserNameSearch", "Customer")'
        }
        );

        $("#UserName").blur(function () {

            var UserName = $('#UserName').val();

            $.ajax({
                url: '@Url.Action("NameFromCode", "Customer")',
                data: {
                    userName: UserName
                },
                success: function (data) {
                    $('#Name').val(data);
                },
                cache: false
            });
        });

        var UpgradeTime1 = '@ViewBag.UpgradeTime1';

        if ($('#UpgradeTime1').length) {
            $('#UpgradeTime1').countdown({
                image: '@Url.Content("~/Images/digits.png")',
                startTime: UpgradeTime1,
                digitWidth: 67,
                digitHeight: 90
            });
        }

        var UpgradeTime2 = '@ViewBag.UpgradeTime2';

        if ($('#UpgradeTime2').length) {
            $('#UpgradeTime2').countdown({
                image: '@Url.Content("~/Images/digits.png")',
                startTime: UpgradeTime2,
                digitImages: 6,
                digitWidth: 67,
                digitHeight: 90
            });
        }

        var validTime = '@ViewBag.ValidTime';

        if ($('#validTime').length) {
            $('#validTime').countdown({
                image: '@Url.Content("~/Images/digits.png")',
                startTime: validTime,
                digitImages: 6,
                digitWidth: 67,
                digitHeight: 90
            });
        }

        jQuery('[data-confirm]').click(function (e) {
            if ($("input:radio[name ='ActiveType']:checked").val() == 1) {
                if ($("#UserName").val() == "") {
                    alert('@MyResources.ErrorUserNameIsRequired');
                    e.preventDefault();
                    $("#UserName").focus();
                    return;
                }

                if ($("#UserNameConfirmed").is(':checked') == false) {
                    alert('@MyResources.ErrorActiveCustomerRequired');
                    e.preventDefault();
                    return;
                }
            }

            if (!confirm(jQuery(this).attr("data-confirm"))) {
                e.preventDefault();
            }
        });

        $('input[type=radio][name=ActiveType]').change(function () {
            if (this.value == '0') {
                $("#UserName").attr("disabled", "disabled");
            }
            else if (this.value == '1') {
                $("#UserName").removeAttr("disabled");
                $("#UserName").focus();
            }
        });

        $("input:radio").val([@Model.ActiveType]);
        if (@Model.ActiveType == 1) {
            $("#UserName").removeAttr("disabled");
            $("#UserName").focus();
        }
    });
</script>
}

<style type="text/css">
    br {
        clear: both;
    }

    .cntSeparator {
        font-size: 54px;
        margin: 10px 7px;
        color: #000;
    }

    .title {
        margin: 7px 3px;
        font-family: Arial;
        font-size: 14px;
        font-weight: bold;
        color:blueviolet;
    }

    .desc {
        margin: 7px 3px;
    }

    .desc div {
        float: left;
        font-family: Arial;
        width: 85px;
        margin-right: 65px;
        font-size: 13px;
        font-weight: bold;
        color: #000;
    }
</style>

@if (@ViewBag.Package1Title != null)
{
    <table style="width:auto; margin-top:5px;" align="center">
        <tr>
            <td>
                <div class="title">@ViewBag.Package1Title - @MyResources.LabelUpgradeTimeTo</div>
            </td>
        </tr>

        <tr>

            @if (@ViewBag.UpgradeTime1 != null)
            {
                <td>
                    <div id="UpgradeTime1"></div>
                </td>
            }
            else
            {
                <td style="height:40px; color:blue; background-color:burlywood;
                        border-radius:12px; font-size:15px" align="center">
                    <div>@MyResources.ErrorUpgradeTimeout</div>
                </td>
            }
        </tr>

        <tr>
            <td>
                <div class="desc">
                    <div>Days</div>
                    <div>Hours</div>
                    <div>Minutes</div>
                    <div>Seconds</div>
                </div>
            </td>
        </tr>

    </table>
}

<br />

@if (@ViewBag.Package2Title != null)
{
    <table style="width:auto" align="center">
        <tr>
            <td>
                <div class="title">@ViewBag.Package2Title - @MyResources.LabelUpgradeTimeTo</div>
            </td>
        </tr>

        <tr>

            @if (@ViewBag.UpgradeTime2 != null)
            {
                <td>
                    <div id="UpgradeTime2"></div>
                </td>
            }
            else
            {
                <td style="height:40px; color:blue; background-color:burlywood;
                        border-radius:12px; font-size:15px" align="center">
                    <div>@MyResources.ErrorUpgradeTimeout</div>
                </td>
            }
        </tr>

        <tr>
            <td>
                <div class="desc">
                    <div>Days</div>
                    <div>Hours</div>
                    <div>Minutes</div>
                    <div>Seconds</div>
                </div>
            </td>
        </tr>

    </table>
}

<br />

    <table style="width:auto" align="center">
        <tr>
        @if (@ViewBag.ValidTime != null)
        {
            <td>
                <div class="title">@MyResources.LabelActiveTime</div>
            </td>
        }
        else
        {
            <td style="height:40px; width:100%; color:blue; background-color:burlywood;
                        border-radius:12px; font-size:15px" align="center">
                @MyResources.LabelIndirectCommissionCondition
            </td>
        }
        </tr>

        <tr>
            <td>
                <div id="validTime"></div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="desc">
                    <div></div>
                    <div></div>
                    <div></div>
                    <div></div>
                </div>
            </td>
        </tr>

    </table>
<br />

@using (Html.BeginForm("Active", "Customer", FormMethod.Get))
{
    <table style="width:auto; padding-left:10px;" align="center">
        <tr style="height:34px;">
            <td colspan="4">
                <input type="radio" id="ActiveType" name="ActiveType"
                       value="0" checked="checked" /> @MyResources.LabelActive&nbsp;&nbsp;
                <input type="radio" id="ActiveType" name="ActiveType" 
                       value="1" /> @MyResources.LabelActiveForOther
            </td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td>
                @MyResources.LabelUserName : &nbsp;&nbsp;
            </td>

            <td style="padding:2px;">
                @Html.TextBox("UserName", Model.UserName,
                    new { @class = "searchtext form-control", @style = "width:120px", @disabled="disabled" })
            </td>

            <td style="padding:2px;">
                @Html.TextBox("Name", Model.Name,
                    new { @class = "searchtext form-control", @readonly = "readonly" })
            </td>
            <td style="padding:2px;">
                @Html.CheckBox("UserNameConfirmed", Model.UserNameConfirmed,
                    new { @class = "form-control-checkbox" })
            </td> 
            <td>
                <input type="submit"
                       data-confirm="@MyResources.ConfirmActive"
                       value="@MyResources.LabelActive" style="height:28px" />
            </td>
            <td valign="middle">
            </td>
        </tr>
        <tr>
            <td colspan="6">
                @Html.ValidationMessage("UserName")
            </td>
        </tr>
        

    </table>
}

<br />
<br />

